import React from 'react';
export const authModes = {
  showOrHide: "showOrHide",
  openOrDisabled: "openOrDisabled",

}
export default function AuthComponent({ auth, children, authMode = authModes.showOrHide,...rest }) {
  const permissions = JSON.parse(localStorage.permissions)
  const ishave = permissions.includes(auth);
  if (authMode === authModes.showOrHide) {
    if (ishave) {
      return React.cloneElement(children,rest);
    } else {
      return null;
    }
  } else {
    //开放或者禁用
    if (ishave) {
      return  React.cloneElement(children,rest);
    } else {
      return React.cloneElement(children, { disabled: true, title: "对不起，你莫得权限" })
    }
  }

} 